package WaitNotify.demo2;
import java.io.IOException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2022-12-25
 * Time: 14:09
 */
public class Main {
    public static void main(String[] args) {
        GuardedObject guardedObject = new GuardedObject();
        //线程1要计算好的结果->获取结果
        new Thread(()->{
            System.out.println("线程1等待结果中!!!");
            try {
                Object object = guardedObject.get(1000);
                System.out.println("获取的结果为" + object);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t1").start();

        new Thread(()->{
            System.out.println("线程2下载中...");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            guardedObject.complete(null);
        },"t2").start();
    }
}
